
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<span style="font-size:18px;">
<html>
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" type="text/css" href="attendance/css/bootstrap.min.css" />
    <link rel="stylesheet" type="text/css" href="attendance/css/commonly-used-show.css" />
    <script type="text/javascript" src="attendance/js/jquery.min.js"></script>
    <script type="text/javascript" src="attendance/js/bootstrap.js" ></script>

    <title>考勤记录</title>

    <style type="text/css">
        td, th {
            text-align: center;
        }
    </style>
</head>

<body class="mybody">


<jsp:include page="theTopMenuUser.jsp" />

<div class="container-fluid">
    <div class="row">
        <div class="col-md-12">
    <div class="col-md-12">
                    <div class="panel panel-primary">
                        <div class="panel-body">
                            <div >
                                <div>
                                    <h3 style="text-align: center">我的考勤信息</h3>
                                    <table border="1" class="table table-bordered table-hover">
                                        <thead>
                                        <tr class="success">
                                            <th>序号</th>
                                            <th>姓名</th>
                                            <th>提交时间</th>
                                            <th>上课打卡时间</th>
                                            <th>上课打卡状态</th>
                                            <th>下课打卡时间</th>
                                            <th>下课打卡状态</th>
                                            <th>操作</th>
                                        </tr>
                                        </thead>

                                        <tbody id="tbody-result">

                                        </tbody>

                                    </table>

                                    <div class="text-center">
                                        <label id="user_null" style="color: red"></label>
                                    </div>

                                </div>
                            </div>
                        </div>
                    </div>
    </div>
</div>
    </div>
</div>






<script type="text/javascript">
    var userdt = JSON.parse(sessionStorage.getItem("user"));
    var coursely = JSON.parse(sessionStorage.getItem("course"));
    var userNull = document.getElementById("user_null");
    if (userdt.result.userName != null){
        $("#usname").text(userdt.result.userName);
    }else {
        $("#usname").text(userdt.result.userLoginName);
    }

    window.onload = function(){
        leaveInfo();
    }

    function leaveInfo(){
        var postUrl = "${pageContext.request.contextPath}/member/queryClockRecord";

        var str = {
            "userId": userdt.result.id,
            "courseId": coursely.result.id
        };

        $.ajax({
            type:"post",
            url:postUrl,
            headers: {
                "Content-Type":"application/json"
            },
            data:JSON.stringify(str),
            contentType: "application/json; charset=utf-8",
            dataType:"json",
            success:function(data){
                if (data.status == "0"){
                    userNull.innerHTML = data.msg;
                }else {
                    var strtab = "";
                    var stState = "";
                    var enState = "";
                    //清空表格数据
                    $("#tbody-result").html("");

                    var conter = 1;
                    for (var i = 0; i < data.result.length; i++) {
                        if (data.result[i].startAttendState === "1"){
                            stState = "正常";
                        }else if (data.result[i].startAttendState === "2"){
                            stState = "迟到";
                        }else if (data.result[i].startAttendState === "3"){
                            stState = "早退";
                        }else if (data.result[i].startAttendState === "4"){
                            stState = "请假";
                        }else if (data.result[i].startAttendState === "5"){
                            stState = "缺卡";
                        }else {
                            stState = "未知";
                        }

                        if (data.result[i].endAttendState === "1"){
                            enState = "正常";
                        }else if (data.result[i].endAttendState === "2"){
                            enState = "迟到";
                        }else if (data.result[i].endAttendState === "3"){
                            enState = "请假";
                        }else if (data.result[i].endAttendState === "4"){
                            enState = "请假";
                        }else if (data.result[i].endAttendState === "5"){
                            enState = "缺卡";
                        }else {
                            enState = "未到时间";
                        }

                        var signTime = "";
                        if(data.result[i].endAttendDate != null){
                            signTime = data.result[i].endAttendDate + " " + data.result[i].endAttendTime;
                        }else {
                            signTime = "未到时间";
                        }

                        strtab = "<tr>" + "<td>" + conter + "</td>"
                            + "<td>" + data.result[i].userName + "</td>"
                            + "<td>" + data.result[i].createTime + "</td>"
                            + "<td>" + data.result[i].startAttendDate + " " + data.result[i].startAttendTime + "</td>"
                            + "<td>" + stState + "</td>"
                            + "<td>" + signTime + "</td>"
                            + "<td>" + enState + "</td>"
                            + "<td>" + "<a class=\"btn btn-default btn-sm\" href=${pageContext.request.contextPath}/checkRecord?id=" + data.result[i].id +  ">" + "查看" + "</a>" + "</td>"
                            + "</tr>";
                        $("#tbody-result").append(strtab);//将数据追加进表格

                        conter++;
                    }
                }

            },
            error:function(xhr,state,errorThrown){
                //alert("发生网络错误，错误码为：" + xhr.status)
                location.href = "${pageContext.request.contextPath}/error";
            }
        });
    }

</script>

</body>
</html>
</span>